package cn.springmvc.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.springmvc.model.Step1;
import cn.springmvc.model.Step2;
import cn.springmvc.model.Step3;
import cn.springmvc.model.Step4;
import cn.springmvc.model.Step5;
import cn.springmvc.model.Step6;
import cn.springmvc.model.Step7;
import cn.springmvc.model.Step8;
import cn.springmvc.service.Step1Service;
import cn.springmvc.service.Step2Service;
import cn.springmvc.service.Step3Service;
import cn.springmvc.service.Step4Service;
import cn.springmvc.service.Step5Service;
import cn.springmvc.service.Step6Service;
import cn.springmvc.service.Step7Service;
import cn.springmvc.service.Step8Service;

@Controller
public class ZuowuApiController {
	@Autowired
	private Step1Service step1Service;
	@Autowired
	private Step2Service step2Service;
	@Autowired
	private Step3Service step3Service;
	@Autowired
	private Step4Service step4Service;
	@Autowired
	private Step5Service step5Service;
	@Autowired
	private Step6Service step6Service;
	@Autowired
	private Step7Service step7Service;
	@Autowired
	private Step8Service step8Service;
	@RequestMapping(value="/getStep1sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep1sByNY(@RequestBody Map<String, Object> args) throws ParseException{
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		String year=(String) args.get("year");
		Step1 lStep1s=step1Service.getStep1ByNameAndNianfen(Integer.parseInt(year),name);
		if (lStep1s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep1s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep2sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep2sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step2 lStep2s=step2Service.getStep2ByNameAndNianfen(year, name);
		if (lStep2s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep2s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep3sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep3sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step3 lStep3s=step3Service.getStep3ByNianfen(year);
		if (lStep3s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep3s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep4sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep4sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step4 lStep4s=step4Service.getStep4ByNameAndNianfen(year, name);
		if (lStep4s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep4s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep5sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep5sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step5 lStep5s=step5Service.getStep5ByNameAndNianfen(year, name);
		if (lStep5s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep5s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep6sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep6sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step6 lStep6s=step6Service.getStep6ByNameAndNianfen(year, name);
		if (lStep6s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep6s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep7sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep7sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step7 lStep7s=step7Service.getStep7ByNameAndNianfen(year, name);
		if (lStep7s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep7s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep8sByNY",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep8sByNY(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step8 lStep8s=step8Service.getStep8ByNameAndNianfen(year, name);
		if (lStep8s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep8s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep1",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep1(@RequestBody Step1 step1){
		Map<String, Object> ret=new HashMap<>();
		if (step1==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step1Service.updateByPrimaryKey(step1)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep2",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep1(@RequestBody Step2 step2){
		Map<String, Object> ret=new HashMap<>();
		if (step2==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step2Service.updateByPrimaryKey(step2)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep3",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep3(@RequestBody Step3 step3){
		Map<String, Object> ret=new HashMap<>();
		if (step3==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step3Service.updateByPrimaryKey(step3)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep4",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep4(@RequestBody Step4 step4){
		Map<String, Object> ret=new HashMap<>();
		if (step4==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step4Service.updateByPrimaryKey(step4)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep5",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep5(@RequestBody Step5 step5){
		Map<String, Object> ret=new HashMap<>();
		if (step5==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step5Service.updateByPrimaryKey(step5)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep6",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep6(@RequestBody Step6 step6){
		Map<String, Object> ret=new HashMap<>();
		if (step6==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step6Service.updateByPrimaryKey(step6)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep7",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep7(@RequestBody Step7 step7){
		Map<String, Object> ret=new HashMap<>();
		if (step7==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step7Service.updateByPrimaryKey(step7)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	
	@RequestMapping(value="/updatestep8",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object updatestep8(@RequestBody Step8 step8){
		Map<String, Object> ret=new HashMap<>();
		if (step8==null) {
			ret.put("message", "failure");
			return ret;
		}
		if (step8Service.updateByPrimaryKey(step8)==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
}
